package com.xt.purchasingsystem.utils;

/**
 * 返回结构处理生成工厂
 */
public class ResultFactory {
    /**
     * 返回对象的成功结果
     *
     * @param message 消息
     * @param data    数据
     * @return
     */
    public static Result buildSuccessResult(String message, Object data) {
        return buildResult(ResultCode.SUCCESS, message, data);
    }

    /**
     * 返回成功的消息
     *
     * @param message 消息
     * @return
     */
    public static Result buildSuccessResult(String message) {
        return buildResult(ResultCode.SUCCESS, message, null);
    }

    /**
     * 返回失败的消息
     *
     * @param message 消息
     * @return
     */
    public static Result buildFailResult(String message) {
        return buildResult(ResultCode.FAIL, message, null);
    }

    /**
     * 返回服务内部错误的消息
     * @param message
     * @return
     */
    public static Result buildErrorResult(String message) {
        return buildResult(ResultCode.INTERNAL_SERVER_ERROR, message, null);
    }

    public static Result buildResult(ResultCode resultCode, String message, Object data) {
        return new Result(resultCode.code, message, data);
    }

}
